package org.raphaello.core;

import android.util.Log;

public class Property{
	
	private static final String TAG = "Property";
	
	public enum ValueType { 
		NUMBER, PATH, COLOR, PROPERTY_NAME, PROPERTY_VALUE, PRIMITIVE, STATE;
		
	};
	
	private String mName;
	private ValueType mType;
	private Object mValue;
	
	
	public Property(String name, String type, String defaultValue){
		mName = name;
		
		if(type.equals("Number")){
			mType = ValueType.NUMBER;
		}
		else if(type.equals("Color")){
			mType = ValueType.COLOR;
		}
		else if(type.equals("Path")){
			mType = ValueType.PATH;
		}
		else if(type.equals("PropertyName")){
			mType = ValueType.PROPERTY_NAME;
		}
		else if(type.equals("PropertyValue")){
			mType = ValueType.PROPERTY_VALUE;
		}
		else if(type.equals("Primitive")){
			mType = ValueType.PRIMITIVE;
		}
		else if(type.equals("State")){
			mType = ValueType.STATE;
		}
		else{
			Log.e(TAG, "Unknown type of property value");
		}
		
		if(defaultValue != null){
			fillValue(defaultValue);
		}
		else{
			mValue = null;
		}
		
	}
	
	public Property(String name, String type){
		this(name, type, null);
	}
	
	public String getName(){
		return mName;
	}
	
	public ValueType getType(){
		return mType;
	}
	
	
	public void fillValue(String value){
		switch(mType){
		case NUMBER:
			mValue = new Integer(value);
			break;
		case COLOR:
			mValue = value;
			break;
		case PATH:
			mValue = value;
			break;
		default:
			mValue = value;
			break;
		}
	}
	
	public Object getValue(){
		return mValue;
	}
	
	public boolean isFilled(){
		return (mValue != null);
	}
}
